package main

import (
	"awesomeProject/src/main/db"
	"awesomeProject/src/main/router"
)

type  DemoOrder struct {
	ID	int 			`gorm:"AUTO_INCREMENT;primaryKey"`
	Name string			`gorm:"default:'goudan'"`
	OrderNo string
	UserName string		`gorm:"default:'zhangsan'"`
	Amount float64
	Status string
	FileUrl string
}

func main() {


	db.NewDB()
	//1. 初始化配置


	//2. 初始化routers
	router.InitRouters()

	//3. 初始化数据库
	// db.Init()

	////GET请求方式 /hello请求路径
	//Router.GET("/hello", func(c *gin.Context) {
	//	//c.JSON(200,gin.H{
	//	name := c.Param("name")
	//	action := c.Param("action")
	//	action = strings.Trim(action,"/")
	//	c.String(http.StatusOK,name+"is"+action)
	//	//})
	//})



	//路由
	//router.Init(r)





	// 迁移 schema

	//u := User{OrderNo: "w",Amount: 1234,Status: "alive",FileUrl: "www.baidu,com"}
	//创建
	//db.AutoMigrate(&u)
	//db.Create(&DemoOrder{OrderNo: "w",Amount: 1234,Status: "alive",FileUrl: "www.baidu,com"})
	//fmt.Println("受影响的行数一共",db.Create(&DemoOrder{OrderNo: "w",Amount: 1234,Status: "alive",FileUrl: "www.baidu,com"}).RowsAffected,"行")


	//使用map插入多个数据
	/*db.Model(&DemoOrder{}).Create([]map[string]interface{}{
		{"OrderNo": "w","Amount": 12334,"Status": "alive","FileUrl": "www.baidu,com"},
		{"OrderNo": "z","Amount": 123456,"Status": "alive","FileUrl": "www.google.com"},
	})*/


	// 获取第一条记录（主键升序）
	//db.First(&u,12)//在后面可以跟上想要查找的主键参数，本例为查找主键id=2的第一条数据

	// 获取一条记录，不指定排序字段，同样可以带参数
	//db.Take(&u)
	//fmt.Println(u)

	// 获取最后一条记录（主键降序）
	//db.Last(&u)

	// 获取全部记录
	//db.Find(&u)
	//fmt.Println(db.Find(&u).RowsAffected)

	//根据给出的关键字查询出匹配的结果
	//db.Where("id = ?", 8).First(&u)
	//fmt.Println(&u)

	//查询id不等于7的最后一条数据
	//db.Not("id = ?",8).Last(&u)
	//fmt.Println(&u)
	// Create
	//db.Create(&Product{Code: "L1212", Price: 1000})
	//
	//// Read
	//var product Product
	//db.First(&product, 1) // find product with id 1
	//db.First(&product, "code = ?", "L1212") // find product with code l1212
	//


	// Update - update product's price to 2000

	// 条件更新
	//db.Model(&u).Where("amount = ?", 12334).Update("name", "hello")

	//db.Model(&product).Update("Price", 2000)
	//


	//// Delete - delete product

	//db.Delete(&DemoOrder{},4)

}